home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / MONITOR_CLIENT_WIN32.PY < prev    next >
Encoding:
Python Source  |  2000-06-02  |  1.2 KB  |  54 lines

  1. # -*- Mode: Python; tab-width: 4 -*-
  2.  
  3. # monitor client, win32 version
  4.  
  5. # since we can't do select() on stdin/stdout, we simply
  6. # use threads and blocking sockets.  <sigh>
  7.  
  8. import regsub
  9. import socket
  10. import string
  11. import sys
  12. import thread
  13. import md5
  14.  
  15. def hex_digest (s):
  16.     m = md5.md5()
  17.     m.update (s)
  18.     return string.join (
  19.         map (lambda x: hex (ord (x))[2:], map (None, m.digest())),
  20.         '',
  21.         )
  22.  
  23. def reader (lock, sock, password):
  24.     # first grab the timestamp
  25.     ts = sock.recv (1024)[:-2]
  26.     sock.send (hex_digest (ts+password) + '\r\n')
  27.     while 1:
  28.         d = sock.recv (1024)
  29.         if not d:
  30.             lock.release()
  31.             print 'Connection closed.  Hit <return> to exit'
  32.             thread.exit()
  33.         sys.stdout.write (d)
  34.         sys.stdout.flush()
  35.  
  36. def writer (lock, sock, barrel="just kidding"):
  37.     while lock.locked():
  38.         sock.send (
  39.             sys.stdin.readline()[:-1] + '\r\n'
  40.             )
  41.  
  42. if __name__ == '__main__':
  43.     if len(sys.argv) == 1:
  44.         print 'Usage: %s host port'
  45.         sys.exit(0)
  46.     print 'Enter Password: ',
  47.     p = raw_input()
  48.     s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
  49.     s.connect ((sys.argv[1], string.atoi(sys.argv[2])))
  50.     l = thread.allocate_lock()
  51.     l.acquire()
  52.     thread.start_new_thread (reader, (l, s, p))
  53.     writer (l, s)
  54.